package com.aiss.ws.activity;

import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.aiss.ws.R;
import com.aiss.ws.utils.Command;
import com.aiss.ws.utils.Futil;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * Created by chenqiang on 16/5/17.
 */
@EActivity(R.layout.activity_setting)
public class SettingActivity extends BaseActivity {

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                if (dialog != null) {
                    dialog.cancel();
                    showMessage("清除成功");
                }
            }
        }
    };

    @ViewById(R.id.title)
    TextView title_tv;

    private ProgressDialog dialog;


    @Click(R.id.back)
    void setBack(){
        finish();
    }

    @AfterViews
    void init(){
        title_tv.setText("设置");
    }

    @Click(R.id.rel_changepassword)
    void rel_changepassword(){
        ChangePasswordActivity_.intent(this).start();
    }

    @Click(R.id.rel_aboutwe)
    void rel_aboutwe(){
        CallMeActivity_.intent(this).start();
    }

    @Click(R.id.rel_clean)
    void rel_clean(){
        dialog = new ProgressDialog(this);
        dialog.setMessage("清除缓存中");
        dialog.show();
        new Thread() {
            @Override
            public void run() {
                super.run();

                try {
                    Thread.sleep(1000);
                    handler.sendEmptyMessage(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }.start();
    }

    /**
     * 退出登录
     */
    @Click(R.id.exit_tv)
    void exit_tv() {
        Futil.saveValue(this, Command.SESSION_KEY,"",2);
        Futil.saveValue(this, Command.MEMBER_ID,"",2);
        if(HomeActivity.getActivity()!=null&&!HomeActivity.getActivity().isFinishing()){
            HomeActivity.getActivity().finish();
        }
        HomeActivity_.intent(this).start();
        RegistActivity_.intent(this).start();
        finish();

    }




}
